﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AutoGenTool.Core
{
    public class ClassInfoContext
    {
        public IReadOnlyList<string> Namespaces { get; private set; }
        public string CurrentNamespace { get; private set; }
        public string ClassName { get; private set; }

        public ClassInfoContext(IEnumerable<string> namespaces, string currentNamespace, string className)
        {
            Namespaces = new List<string>(namespaces);
            CurrentNamespace = currentNamespace;
            ClassName = className;
        }

        public override string ToString()
        {
            return $"{CurrentNamespace}.{ClassName}";
        }
    }

    public class MethodInfoContext
    {
        public IReadOnlyList<string> Namespaces { get; private set; }
        public string CurrentNamespace { get; private set; }
        public string ClassName { get; private set; }
        public string MethodName { get; private set; }
        public IReadOnlyList<ArgumemtInfo> ArgumentList { get; private set; }
        public string ReturnType { get; private set; }
        public string Modifier { get; private set; }

        public MethodInfoContext(IEnumerable<string> namespaces,
            string currentNamespace,
            string className,
            string name,
            IEnumerable<ArgumemtInfo> infoList,
            string returnType,
            string modifier)
        {
            Namespaces = new List<string>(namespaces);
            CurrentNamespace = currentNamespace;
            ClassName = className;
            MethodName = name;
            ArgumentList = new List<ArgumemtInfo>(infoList);
            ReturnType = returnType;
            Modifier = modifier;
        }

        public override string ToString()
        {
            return $"{CurrentNamespace}.{ClassName}.{MethodName}";
        }

    }

    ///<summary>函数参数的信息。</summary>
    public class ArgumemtInfo
    {
        public string Type { get; private set; }
        public string Name { get; private set; }

        public ArgumemtInfo(string type, string name)
        {
            Type = type;
            Name = name;
        }

        public override string ToString()
        {
            return $"{Type} {Name}";
        }
    }

    ///<summary>自动生成项目的配置信息。</summary>
    public class AutoGenConfig
    {
        ///<summary>csproj所在文件夹，不是.csproj文件夹本身</summary>
        public string ProjectRoot { get; set; }

        ///<summary>缓存文件夹位置</summary>
        public string CacheLocation { get; set; }

        ///<summary>忽略文件夹，解析器不会进入该文件夹。</summary>
        public string[] IgnoreDir { get; set; }
        //public string[] IncludeFile { get; set; }

        ///<summary>生成的代码所在的文件夹。</summary>
        public string GenCodeDir { get; set; }

        ///<summary>是否使用缓存加速解析。</summary>
        public bool UseCache { get; set; }
    }

    public class DbFileRecord
    {
        public string Id { get; set; }
        public string Sha256 { get; set; }

        public DbFileRecord(string id, string sha256)
        {
            Id = id;
            Sha256 = sha256;
        }

        public DbFileRecord()
        {

        }
    }
}
